<template>
  <el-form :model="ruleForm" ref="ruleForm" :label-position="top" :rules="rules"
           :class="isEdit?'':'formItem'">
    <el-card class="box-card" shadow="never">
      <div slot="header" class="header-card">
        <span class="header-card-title">更换轮胎反馈</span>
      </div>
      <el-row :gutter="24">
        <el-col :span="8">
          <el-form-item label="实际更换轮胎开始时间:" prop="actualStartTime">
            <el-date-picker type="date" v-model="ruleForm.actualStartTime" v-if="isEdit"
                            value-format='yyyy-MM-dd' style="width: 100%;" placeholder="选择实际更换轮胎开始时间">
            </el-date-picker>
            <span v-else>{{ ruleForm.actualStartTime }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="实际更换轮胎结束时间:" prop="actualEndTime">
            <el-date-picker type="date" v-model="ruleForm.actualEndTime" v-if="isEdit"
                            value-format='yyyy-MM-dd' style="width: 100%;" placeholder="实际更换轮胎结束时间">
            </el-date-picker>
            <span v-else>{{ ruleForm.actualEndTime }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="是否个人垫付:" prop="feedbackAdvancePayment">
            <el-select v-model="ruleForm.feedbackAdvancePayment" @change="handleSelect" v-if="isEdit" placeholder="请是否个人垫付"
                       style="width: 100%;">
              <el-option v-for="v in dict.type.pay_personal" :label="v.label" :key="v.value" :value="Number(v.value)">
              </el-option>
            </el-select>
            <span v-else>  {{ selectDictLabel(dict.type.pay_personal, ruleForm.feedbackAdvancePayment) }}</span>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="24">
        <el-col :span="8">
          <el-form-item label="付款类型:" prop="payType">
            <el-select v-model="ruleForm.payType"  v-if="isEdit" placeholder="请选择付款类型" style="width: 100%;">
              <el-option v-for="v in dict.type.pay_type" :label="v.label" :key="v.value" :value="Number(v.value)">
              </el-option>
            </el-select>
            <span v-else>  {{ selectDictLabel(dict.type.pay_type, ruleForm.payType) }}</span>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="24">
        <el-col :span="24">
          <el-form-item label="更换轮胎完成照片:">
            <image-common v-model="ruleForm.replaceCompleteUrl" :disabled="!isEdit"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="24">
        <el-col :span="24">
          <el-form-item label="结算单上传:">
            <image-common v-model="ruleForm.balanceUrl" :limit="20" :disabled="!isEdit" :upType="2"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="24">
        <el-col :span="24">
          <el-form-item label="更换轮胎意见反馈:">
            <el-input v-if="isEdit" placeholder="更换轮胎意见反馈" type="textarea" :rows="4"
            :maxlength="500"  v-model="ruleForm.replaceFeedback"></el-input>
            <span v-else>{{ ruleForm.replaceFeedback }}</span>
          </el-form-item>
        </el-col>
      </el-row>

    </el-card>
  </el-form>
</template>

<script>
import {effectTime} from "@/utils/libs/effectDate.js"
export default {
  name: "tirFeedback",
  dicts: ['pay_type', 'pay_personal'],
  components: {
    ImgUpload: () => import('../../../components/ImgUpload'),
    UploadFile: () => import('../../../../components/UploadFile')
  },
  model: {
    prop: 'detailForm',
    event: 'update:detailForm',
  },

  props: {
    detailForm: {
      type: Object,
      default: {},
    },
    state: {
      type: String,
      default: '',
    }
  },
  computed: {
    ruleForm: {
      get() {
        let that = this
        const proxy = new Proxy(that.detailForm, {
          get(target, key) {
            return Reflect.get(target, key)
          },
          set(target, key, value) {
            that.$emit('update:detailForm', {...target, [key]: value})
            return true
          }
        })
        return proxy
      }
    },
    isEdit() {
      let bool;
      switch (this.state) {
        case "write":
          bool = true;
          break;
        case "disabled":
          bool = false;
          break;
        case "readonly":
          bool = false;
          break;
      }
      return bool;
    },
    top() {
      if (this.isEdit) {
        return 'top'
      } else {
        return 'right'
      }
    }
  },
  watch: {},
  data() {
    var start = (rule, value, callback) => {
      let that = this
      effectTime(rule, value, callback,
          that.ruleForm.actualStartTime,
          that.ruleForm.actualEndTime,
          '实际更换轮胎开始时间',
          '实际更换轮胎结束时间'
      )
    };
    var end = (rule, value, callback) => {
      let that = this
      effectTime(rule, value, callback,
          that.ruleForm.actualStartTime,
          that.ruleForm.actualEndTime,
          '实际更换轮胎开始时间',
          '实际更换轮胎结束时间'
      )
    };
    return {
      rules: {
        actualStartTime: [{required: this.state === 'write', validator: start, trigger: 'change'}],
        actualEndTime: [{required: this.state === 'write', validator: end, trigger: 'change'}],
        feedbackAdvancePayment: [{
          required: this.state === 'write',
          message: '请选择是否支个人垫付',
          trigger: 'change'
        }],
        payType: [{required: this.state === 'write', message: '请选择付款类型', trigger: 'change'}],
      }
    };
  },

  created() {
  },
  mounted() {
  },
  methods: {
    handleSelect(val){
      this.detailForm.feedbackAdvancePayment = this.ruleForm.feedbackAdvancePayment  =val
      this.detailForm.payType =  this.ruleForm.payType =val
    },
    valid() {
      return new Promise((resolve) => {
        this.$refs.ruleForm.validate((valid) => {
          resolve(valid);
        });
      })
    },
  },
};
</script>

<style scoped lang="scss">
@import "@/styles/cwgd/formScss.scss";
</style>


